/**
 * 时间戳转 yyyy-MM-dd HH:mm:ss格式
 *
 * @param value
 * @returns {string}
 */
export function timestampToDateTime(value = new Date()) {
  let date = new Date(value);
  let y = date.getFullYear(),
    m = date.getMonth() + 1,
    d = date.getDate(),
    h = date.getHours(),
    i = date.getMinutes(),
    s = date.getSeconds();
  if (m < 10) {
    m = '0' + m;
  }
  if (d < 10) {
    d = '0' + d;
  }
  if (h < 10) {
    h = '0' + h;
  }
  if (i < 10) {
    i = '0' + i;
  }
  if (s < 10) {
    s = '0' + s;
  }
  return y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s;
}

/**
 * 时间戳转 yyyy-MM-dd HH:mm:ss格式(每月一号)
 *
 * @param value
 * @returns {string}
 */
export function timestampToMonthTime() {
  let date = new Date();
  let y = date.getFullYear(),
    m = date.getMonth() + 1,
    d = '01',
    h = date.getHours(),
    i = date.getMinutes(),
    s = date.getSeconds();
  if (m < 10) {
    m = '0' + m;
  }
  // if (d < 10) { d = '0' + d; }
  if (h < 10) {
    h = '0' + h;
  }
  if (i < 10) {
    i = '0' + i;
  }
  if (s < 10) {
    s = '0' + s;
  }
  return y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s;
}


/**
 * 时间戳转 yyyy-MM-dd
 *
 * @param value
 * @returns {string}
 */
export function timestampToDate(value = new Date()) {
  let date = new Date(value);
  let y = date.getFullYear(),
    m = date.getMonth() + 1,
    d = date.getDate(),
    h = date.getHours(),
    i = date.getMinutes(),
    s = date.getSeconds();
  if (m < 10) {
    m = '0' + m;
  }
  if (d < 10) {
    d = '0' + d;
  }
  if (h < 10) {
    h = '0' + h;
  }
  if (i < 10) {
    i = '0' + i;
  }
  if (s < 10) {
    s = '0' + s;
  }
  return y + '-' + m + '-' + d;
}

/**
 * 时间戳转每天的23:59:59 yyyy-MM-dd 24:00:00
 *
 * @param value
 * @returns {string}
 */
export function timestampToDate24(value = new Date()) {
  let date = new Date(value);
  let y = date.getFullYear(),
    m = date.getMonth() + 1,
    d = date.getDate(),
    h = date.getHours(),
    i = date.getMinutes(),
    s = date.getSeconds();
  if (m < 10) {
    m = '0' + m;
  }
  if (d < 10) {
    d = '0' + d;
  }
  if (h < 10) {
    h = '0' + h;
  }
  if (i < 10) {
    i = '0' + i;
  }
  if (s < 10) {
    s = '0' + s;
  }
  return y + '-' + m + '-' + d + ' ' + '23:59:59';
}


/**
 * 时间戳转 yyyy年MM月dd日 星期x HH:mm:ss格式
 *
 * @param value
 * @returns {string}
 */
export function timestampToDateTimeCN(value = new Date()) {
  let date = new Date(value);
  let y = date.getFullYear(),
    m = date.getMonth() + 1,
    d = date.getDate(),
    h = date.getHours(),
    i = date.getMinutes(),
    s = date.getSeconds(),
    w = date.getDay();
  let week = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
  if (m < 10) {
    m = '0' + m;
  }
  if (d < 10) {
    d = '0' + d;
  }
  if (h < 10) {
    h = '0' + h;
  }
  if (i < 10) {
    i = '0' + i;
  }
  if (s < 10) {
    s = '0' + s;
  }
  return y + '年' + m + '月' + d + '日' + ' ' + week[w] + ' ' + ' ' + h + ':' + i + ':' + s;
}


/**
 * 获取x天之后的时间
 *
 * @param date
 * @param days
 * @returns {Date}
 */
export function addDays(date, days) {
  return new Date(date.getTime() + days * 1000 * 60 * 60 * 24);
}

export function secondsToMinute(time) {
  // 转换为式分秒
  let h = parseInt(time / 60 / 60 % 24)
  h = h < 10 ? '0' + h : h
  let m = parseInt(time / 60 % 60)
  m = m < 10 ? '0' + m : m
  let s = parseInt(time % 60)
  s = s < 10 ? '0' + s : s
  // 作为返回值返回
  return `${m}:${s}`
}
